//
//  AccessoryTableViewCell.m
//  Village
//
//  Created by longrise on 2017/10/11.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "AccessoryTableViewCell.h"
#import "LCDownloadManager.h"
#import "ProgressView.h"

@interface AccessoryTableViewCell ()
@property (nonatomic, strong) ProgressView *prossView;
@end

@implementation AccessoryTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _Accimage = [[UIImageView alloc] init];
        _Accimage.image = [UIImage imageNamed:@"accessory"];
        [self addSubview:_Accimage];
        [_Accimage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(22*kScreenScaleX);//使左边等于self.view的左边，间距为0
            make.top.equalTo(self.mas_top).offset(10*kScreenScaleY);
            make.width.mas_equalTo(19*kScreenScaleX);
            make.height.mas_equalTo(21*kScreenScaleY);
            
        }];
        
        
        self.Acclable = [[UILabel alloc]init];
        self.Acclable.text = @"《附件1》";
        self.Acclable.font = [UIFont systemFontOfSize:16*kScreenScaleX];
        [ self.Acclable setTextAlignment : NSTextAlignmentLeft] ;
        
        [self addSubview:self.Acclable];
        
        [self.Acclable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_Accimage.mas_right).offset(7*kScreenScaleX);//使左边等于self.view的左边，间距为0
            make.width.mas_equalTo(250*kScreenScaleX);
            make.height.mas_equalTo(21*kScreenScaleY);
            make.top.equalTo(self.mas_top).offset(10*kScreenScaleY);
        }];
        
        _Accbutton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_Accbutton setImage:[UIImage imageNamed:@"accessory2"] forState:UIControlStateNormal];
        [_Accbutton addTarget:self action:@selector(accbuttonClick) forControlEvents:UIControlEventTouchUpInside];
        _Accbutton.tag = 1;
        [self addSubview:_Accbutton];
        [_Accbutton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-20*kScreenScaleX);//使左边等于self.view的左边，间距为0
            make.width.mas_equalTo(19);
            make.height.mas_equalTo(19);
            make.top.equalTo(self.mas_top).offset(10*kScreenScaleY);
        }];
        
        
    }
    return self;
}

- (void)setIndex:(NSInteger)index
{
    _index = index;
}

- (void)accbuttonClick
{
    if (self.downBlock) {
        self.downBlock(_index);
    }
}

- (void)setFjStr:(NSString *)fjStr
{
    _fjStr = fjStr;
    
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *filePath = [path stringByAppendingPathComponent:@"policy.plist"];
    // 解档
    NSMutableArray *usersary = [[NSMutableArray alloc]initWithContentsOfFile:filePath];
    BOOL isbool = [usersary containsObject: _fjStr];
    if (isbool == 1){
        [_Accbutton setImage:[UIImage imageNamed:@"down_on"] forState:UIControlStateNormal];
//                _Accbutton.enabled = NO;
    }else{
        [_Accbutton setImage:[UIImage imageNamed:@"accessory2"] forState:UIControlStateNormal];
//                _Accbutton.enabled = NO;
    }
    
//    if ([usersDic objectForKey:_fjStr]) {
//        [_Accbutton setImage:[UIImage imageNamed:@"accessory2"] forState:UIControlStateNormal];
//        _Accbutton.enabled = YES;
//    }
//    else{
//        [_Accbutton setImage:[UIImage imageNamed:@"down_on"] forState:UIControlStateNormal];
//        _Accbutton.enabled = NO;
//    }
//
//    if ([[Globle getInstance] judgeFJIsDownloadWIthFJID:_fjStr]) {
//        [_Accbutton setImage:[UIImage imageNamed:@"down_on"] forState:UIControlStateNormal];
//        _Accbutton.enabled = NO;
//    }
//    else {
//        [_Accbutton setImage:[UIImage imageNamed:@"accessory2"] forState:UIControlStateNormal];
//        _Accbutton.enabled = YES;
//    }
}


@end
